package org.hamster.multidropbox.mainView.view
{
	import org.hamster.common.puremvc.mediator.BaseMediator;
	import org.hamster.multidropbox.dropbox.command.DropboxLinkFoldersCommand;
	import org.hamster.multidropbox.dropbox.event.AppDropboxEvent;
	import org.hamster.multidropbox.mainView.commands.GetPathDetailsCommand;
	import org.hamster.multidropbox.mainView.event.AppFileEvent;
	import org.hamster.multidropbox.mainView.event.MainViewEvent;
	import org.hamster.multidropbox.mainView.model.MainViewFileProxy;
	import org.hamster.multidropbox.mainView.view.file.LinkFolderPanelMediator;
	import org.hamster.multidropbox.mainView.view.file.LinkFolderUploadPanelMediator;
	
	public class MainViewMediator extends BaseMediator
	{
		public static const NAME:String = "org.hamster.multidropbox.mainView.view.MainViewMediator";
		
		public function MainViewMediator(viewComponent:Object=null)
		{
			super(NAME, viewComponent);
		}
		
		override public function onRegister():void
		{
			facade.registerCommand(AppFileEvent.FILE_PATH_CHANGE_REQUEST, GetPathDetailsCommand);
			
			facade.registerProxy(new MainViewFileProxy());
			
			facade.registerMediator(new ImportAccountPanelMediator());
			facade.registerMediator(new LinkFolderPanelMediator());
			facade.registerMediator(new LinkFolderUploadPanelMediator());
			
			facade.registerMediator(new AppMenuBarMediator(app.appMenuBar));
			facade.registerMediator(new LeftPanelViewMediator(app.leftPanelView));
			facade.registerMediator(new FileListCollectionViewMediator(app.fileListCollectionView));
			facade.registerMediator(new LinkFoldersViewMediator(app.linkFoldersView));
			
		}
		
		override public function onRemove():void
		{
			facade.removeCommand(AppFileEvent.FILE_PATH_CHANGE_REQUEST);
			facade.removeCommand(AppDropboxEvent.DROPBOX_LINK_FOLDERS_REQUEST);
			
			facade.removeProxy(MainViewFileProxy.NAME);
			
			facade.removeMediator(AppMenuBarMediator.NAME);
			facade.removeMediator(LinkFolderPanelMediator.NAME);
			facade.removeMediator(LeftPanelViewMediator.NAME);
			facade.removeMediator(ImportAccountPanelMediator.NAME);
			facade.removeMediator(FileListCollectionViewMediator.NAME);
			facade.removeMediator(LinkFoldersViewMediator.NAME);
			
		}
		
		override public function listNotificationInterests():Array
		{
			return [
				MainViewEvent.LINK_FOLDERS_VIEW_SHOW,
				MainViewEvent.LINK_FOLDERS_VIEW_HIDE,
			];
		}
		
		public function handleLinkFoldersViewShow(data:Object):void
		{
			this.app.mainViewStack.selectedIndex = 1;
		}
		
		public function handleLinkFoldersViewHide(data:Object):void
		{
			this.app.mainViewStack.selectedIndex = 0;
		}
		
		public function get app():MainView
		{
			return viewComponent as MainView;
		}
	}
}